package com.hdd.hll.common.response;

import com.hdd.hll.common.cache.ResultCodeCache;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * 返回类 
 * @param <T>
 */
@ApiModel("Api请求返回实体类")
@Data
public class Response<T> implements Serializable{
	private static final long serialVersionUID = 5639511160918517232L;

	private static ResultCodeCache rCode = ResultCodeCache.getInstance();
	

	@ApiModelProperty("请求返回状态码，1100    表示请求成功")
	private String code =  rCode.get("common.success"); //  编号

	
	@ApiModelProperty("返回英文信息")
	private String msgEn = rCode.getMsgEn("common.success");// 英文消息
	
	
	@ApiModelProperty("返回中文信息")
	private String msg = rCode.getMsgZh("common.success");// 中午消息
	
	@ApiModelProperty("返回状态码  true 表示请求成")
	private Boolean success = true;// 是否成功
	
	@ApiModelProperty("返回数据 ，所有的数据 都在data中")
	private  T data = null;// 数据


	public Response() {
		this.code  = rCode.get("common.success");
		this.msgEn  = rCode.getMsgEn("common.success");
		this.msg  = rCode.getMsgZh("common.success");
		this.success  = true;
	}
	public Response(Integer code) {
		String rccc =  rCode.getIdentByCode(code.toString());
		this.code  = rCode.get(rccc);
		this.msgEn  = rCode.getMsgEn(rccc);
		this.msg  = rCode.getMsgZh(rccc);
		if(rccc.equals("common.success")) {
			this.success  = true;
		}else {
			this.success = false;
		}
	}
	public Response(String code) {
		this.code  = rCode.get(code);
		this.msgEn  = rCode.getMsgEn(code);
		this.msg  = rCode.getMsgZh(code);
		
		if(code.equals("common.success")) {
			this.success  = true;
		}else {
			this.success = false;
		}
	}

	public Response(T obj) {
		this.code  = rCode.get("common.success");
		this.msgEn  = rCode.getMsgEn("common.success");
		this.msg  = rCode.getMsgZh("common.success");
		this.data = obj;
		this.success  = true;
	}
}
